package com.rd.teacher.jichao.day15.producer3;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;

public class Producer implements Runnable {
    ArrayBlockingQueue<Integer> queue;

    public Producer(ArrayBlockingQueue<Integer> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
                if (queue.size() == 10) {
                    System.out.println("full,waiting");
                }
                int value = new Random().nextInt(100);
                queue.put(value);
                System.out.println(Thread.currentThread().getName()
                        + " put " + value);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
